@@ -3,6 +3,7 @@ require "twitter" |
||
3 | 3 |
module Agents |
4 | 4 |
class TwitterPublishAgent < Agent |
5 | 5 |
include TwitterConcern |
6 |
+ include LiquidInterpolatable |
|
6 | 7 |
|
7 | 8 |
cannot_be_scheduled! |
8 | 9 |
|
@@ -15,7 +16,7 @@ module Agents |
||
15 | 16 |
|
16 | 17 |
To get oAuth credentials for Twitter, [follow these instructions](https://github.com/cantino/huginn/wiki/Getting-a-twitter-oauth-token). |
17 | 18 |
|
18 |
- You must also specify a `message_path` parameter: a [JSONPaths](http://goessner.net/articles/JsonPath/) to the value to tweet. |
|
19 |
+ You must also specify a `message` parameter, you can use [Liquid](https://github.com/cantino/huginn/wiki/Formatting-Events-using-Liquid) to format the message. |
|
19 | 20 |
|
20 | 21 |
Set `expected_update_period_in_days` to the maximum amount of time that you'd expect to pass between Events being created by this Agent. |
21 | 22 |
MD |
@@ -31,7 +32,7 @@ module Agents |
||
31 | 32 |
def default_options |
32 | 33 |
{ |
33 | 34 |
'expected_update_period_in_days' => "10", |
34 |
- 'message_path' => "text" |
|
35 |
+ 'message' => "{{text}}" |
|
35 | 36 |
} |
36 | 37 |
end |
37 | 38 |
|
@@ -41,7 +42,7 @@ module Agents |
||
41 | 42 |
incoming_events = incoming_events.first(20) |
42 | 43 |
end |
43 | 44 |
incoming_events.each do |event| |
44 |
- tweet_text = Utils.value_at(event.payload, options['message_path']) |
|
45 |
+ tweet_text = interpolate_string(options['message'], event.payload) |
|
45 | 46 |
begin |
46 | 47 |
tweet = publish_tweet tweet_text |
47 | 48 |
create_event :payload => { |
@@ -0,0 +1,10 @@ |
||
1 |
+class MigrateTwitterPublishAgentToLiquid < ActiveRecord::Migration |
|
2 |
+ def change |
|
3 |
+ Agent.where(:type => 'Agents::TwitterPublishAgent').each do |agent| |
|
4 |
+ if (message = agent.options.delete('message_path')).present? |
|
5 |
+ agent.options['message'] = "{{#{message}}}" |
|
6 |
+ agent.save |
|
7 |
+ end |
|
8 |
+ end |
|
9 |
+ end |
|
10 |
+end |
@@ -9,7 +9,7 @@ describe Agents::TwitterPublishAgent do |
||
9 | 9 |
:consumer_secret => "---", |
10 | 10 |
:oauth_token => "---", |
11 | 11 |
:oauth_token_secret => "---", |
12 |
- :message_path => "text" |
|
12 |
+ :message => "{{text}}" |
|
13 | 13 |
} |
14 | 14 |
|
15 | 15 |
@checker = Agents::TwitterPublishAgent.new(:name => "HuginnBot", :options => @opts) |